package com.lj.job.result;

import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.converters.longconverter.LongStringConverter;
import com.lj.job.entity.JobLog;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * <p>
 * 定时任务日志 excel导出参数
 * </p>
 *
 * @author luojing
 * @since 2025-03-20 15:26:16
 */
@Data
public class JobLogExportResult {

    /**
     * 定时任务id
     */
    @ExcelProperty(value = "定时任务id", converter = LongStringConverter.class)
    private Long jobId;

    /**
     * 执行bean的名称
     */
    @ExcelProperty("执行bean的名称")
    private String beanName;

    /**
     * 执行参数
     */
    @ExcelProperty("执行参数")
    private String params;

    /**
     * 是否成功
     */
    @ExcelProperty("是否成功")
    private String succeed;

    /**
     * 错误信息
     */
    @ExcelProperty("错误信息")
    private String error;

    /**
     * 耗时 (单位: ms)
     */
    @ExcelProperty("耗时 (单位: ms)")
    private Integer times;

    @ExcelProperty("日志记录时间")
    private LocalDateTime createTime;

    public static JobLogExportResult of(JobLog entity) {
        if (entity == null) {
            return null;
        }
        JobLogExportResult result = new JobLogExportResult();
        result.setJobId(entity.getJobId());
        result.setBeanName(entity.getBeanName());
        result.setParams(entity.getParams());
        result.setSucceed(Boolean.TRUE.equals(entity.getSucceed()) ? "是" : "否");
        result.setError(entity.getError());
        result.setTimes(entity.getTimes());
        result.setCreateTime(entity.getCreateTime());
        return result;
    }
}
